{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 媒体内容分析 MCA\n",
    "1.登录百度智能云平台官网。\n",
    "* 若没有用户名，请先完成注册，操作请参考注册百度账号。\n",
    "* 若有用户名，登录操作请参考登录。\n",
    "2.登录成功后，选择“产品服务>媒体内容分析 MCA”，进入“视频分析”页面，点击创建视频分析，进入创建视频分析界面。\n",
    "\n",
    "3.MCA支持两种视频导入方式：本地文件导入、BOS 地址导入。\n",
    "\n",
    "* 本地文件导入：您需要先指定本地视频上传后存储本地视频的BOS 地址，如果还未创建BOS Bucket，请参考 BOS 操作指南创建，存储 BOS 地域目前仅支持北京，然后选择本地音视频（最多支持批量上传20个音视频），最后选择分析模板，点击确定则发起分析。\n",
    "\n",
    "* BOS地址导入：对象存储 BOS 地域仅支持北京，选择BOS 中 Bucket 路径以及Bucket下待分析音视频（最多支持批量导入20个音视频），然后选择分析模板，点击确定则发起分析。\n",
    "\n",
    "输入限制：\n",
    "\n",
    "* 文件格式：3gpp、asf/wmv、avi、flv/f4v、mkv、mov/mp4/m4a、mp3、mp2、mpeg/mpg、ts/ogg、mts、wmv/wma、rm/rmvb、webm等；\n",
    "* 视频编码标准：H.264、H.263/H.263+、MPEG-1/2/4、VP8/9、Quicktime、RealVideo、WMV、MJPEG等；\n",
    "* 音频编码标准：MP1、MP2、MP3、AAC、AC-3、WMA、PCM、ADPCM、AMR、RealAudio、Vorbis、DSD等；\n",
    "* 分析时长（向下取整）5个小时以内，分辨率大于等于320 x 240，小于等于2560 x 1440；\n",
    "* 分析视频的audio、video编码信息须至少存在一个，不能为空；\n",
    "* 可批量上传音视频文件，最多可同时上传20个文件。\n",
    "4.分析过程中可以看到分析状态（排队中—>分析中—>分析完成）。如果分析失败，可以将鼠标移到分析失败旁边的图标上查看失败原因。\n",
    "\n",
    "分析结束状态（包括分析完成和分析失败）可以重新发起分析。若分析完成，则可查看分析结果。\n",
    "\n",
    "5.点击分析完成视频的\"查看详情\"按钮，即可查看视频分析的结果.\n",
    "\n",
    "### 接口\n",
    "请求语法  \n",
    "'''  \n",
    "PUT /v{version}/media HTTP/1.1  \n",
    "host: vca.bj.baidubce.com  \n",
    "authorization: <bce-authorization-string>  \n",
    "content-type: application/json  \n",
    "'''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分析BOS类型媒资\n",
    "\n",
    "PUT /v1/media HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n",
    "\t\n",
    "{\n",
    "    \"source\": \"bos://samplebucket/sample.mp4\", // 也支持图片bos://demobucket/demo.jpg\n",
    "    \"preset\": \"customer_preset_name\",\n",
    "    \"notification\": \"customer_notification_name\"\n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HTTP/1.1 200 OK\n",
    "{\n",
    "    \"source\": \"bos://samplebucket/sample.mp4\",\n",
    "    \"preset\": \"customer_preset_name\",\n",
    "    \"status\": \"PROVISIONING\",\n",
    "    \"percent\": 0,\n",
    "    \"createTime\": \"2018-10-09T08:05:58Z\",\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分析 VOD 媒资原视频\n",
    "\n",
    "PUT /v1/media HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n",
    "    \n",
    "{\n",
    "  \"source\": \"vod://mda-fhepatsnpn4rk9z\",\n",
    "  \"preset\": \"customer_preset_name\",\n",
    "  \"notification\": \"customer_notification_name\"\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HTTP/1.1 200 OK\n",
    "\n",
    "{\n",
    "    \"source\": \"vod://mda-fhepatsnpn4rk9z\",\n",
    "    \"mediaId\": \"mda-fhepatsnpn4rk9z\",\n",
    "    \"title\": \"media title\",\n",
    "    \"preset\": \"customer_preset_name\",\n",
    "    \"status\": \"PROVISIONING\",\n",
    "    \"percent\": 0,\n",
    "    \"notification\": \"customer_notification_name\",\n",
    "    \"createTime\": \"2018-10-09T08:05:58Z\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分析 VOD 媒资转码后视频\n",
    "\n",
    "PUT /v1/media HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n",
    "{\n",
    "  \"source\": \"vod://mda-fhepatsnpn4rk9z-mp4\",\n",
    "  \"preset\": \"customer_preset_name\",\n",
    "  \"notification\": \"customer_notification_name\"\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HTTP/1.1 200 OK\n",
    "\n",
    "{\n",
    "\t\"source\": \"vod://mda-fhepatsnpn4rk9z-mp4\",\n",
    "\t\"mediaId\": \"mda-fhepatsnpn4rk9z\",\n",
    "\t\"title\": \"media title\",\n",
    "\t\"preset\": \"customer_preset_name\",\n",
    "\t\"status\": \"PROVISIONING\",\n",
    "\t\"percent\": 0,\n",
    "\t\"notification\": \"customer_notification_name\",\n",
    "\t\"createTime\": \"2018-10-09T08:05:58Z\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分析 URL 视频\n",
    "\n",
    "PUT /v1/media HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n",
    "\t\n",
    "{\n",
    "    \"source\": \"https://vca-customer.baidu.com/media.mp4\", // 也支持图片https://vca-customer.baidu.com/media.jpg\n",
    "    \"preset\": \"customer_preset_name\",\n",
    "    \"notification\": \"customer_notification_name\"\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HTTP/1.1 200 OK\n",
    "\t\n",
    "{\n",
    "    \"source\": \"https://vca-customer.baidu.com/media.mp4\",\n",
    "    \"preset\": \"customer_preset_name\",\n",
    "    \"status\": \"PROVISIONING\",\n",
    "    \"percent\": 0,\n",
    "    \"notification\": \"customer_notification_name\",\n",
    "    \"createTime\": \"2018-10-09T08:05:58Z\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分析包含鉴权参数的 URL 视频\n",
    "\n",
    "PUT /v1/media HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n",
    "\t\n",
    "{\n",
    "    \"source\": \"https://vca-customer.baidu.com/media.mp4\", // 也支持图片https://vca-customer.baidu.com/media.jpg\n",
    "    \"auth\": \"authorization=some_authorization_info\"\n",
    "    \"preset\": \"customer_preset_name\",\n",
    "    \"notification\": \"customer_notification_name\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HTTP/1.1 200 OK\n",
    "\t\n",
    "{\n",
    "    \"source\": \"https://vca-customer.baidu.com/media.mp4\",\n",
    "    \"preset\": \"customer_preset_name\",\n",
    "    \"status\": \"PROVISIONING\",\n",
    "    \"percent\": 0,\n",
    "    \"notification\": \"customer_notification_name\",\n",
    "    \"createTime\": \"2018-10-09T08:05:58Z\"\n",
    "}\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 查询结果\n",
    "请求语法  \n",
    "'''\n",
    "GET /v{version}/media HTTP/1.1  \n",
    "host: vca.bj.baidubce.com  \n",
    "authorization: <bce-authorization-string>  \n",
    "content-type: application/json  \n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查询 BOS 视频分析结果\n",
    "\n",
    "GET /v1/media?source=bos%3a%2f%2ftestbucket%2fdir%2fvideo.mp4 HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查询 VOD 媒资原视频分析结果\n",
    "\n",
    "GET /v1/media?source=vod%3a%2f%2fmda-fhepatsnpn4rk9z HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查询 VOD 媒资转码后视频分析结果\n",
    "\n",
    "GET /v1/media?source=vod%3a%2f%2fmda-fhepatsnpn4rk9z-mp4 HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#查询 URL 视频分析结果\n",
    "\n",
    "GET /v1/media?source=http%3a%2f%2ftest.domain.com%2fdir%2fvideo.mp4 HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HTTP/1.1 200 OK\n",
    "\n",
    "{\n",
    "    \"source\": \"vod://mda-fhepatsnpn4rk9z\",\n",
    "    \"mediaId\": \"mda-fhepatsnpn4rk9z\",\n",
    "    \"title\": \"media title\",\n",
    "    \"description\": \"\",\n",
    "    \"preset\": \"customer_preset_name\",\n",
    "    \"status\": \"FINISHED\",\n",
    "    \"percent\": 100,\n",
    "    \"notification\": \"customer_notification_name\",\n",
    "    \"createTime\": \"2018-10-09T12:00:00Z\",\n",
    "    \"publishTime\": \"2018-10-09T12:06:48\",\n",
    "    \"results\": [{\n",
    "        \"type\": \"scenario\",\n",
    "        \"result\": [{\n",
    "            \"attribute\": \"新闻\",\n",
    "            \"source\": \"scenario_classify\",\n",
    "            \"confidence\": 68,\n",
    "        }]\n",
    "    }]\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 查询视频分析中间任务结果\n",
    "\n",
    "请求语法  \n",
    "'''  \n",
    "GET /v{version}/media/<type>?source={source} HTTP/1.1  \n",
    "host: vca.bj.baidubce.com  \n",
    "authorization: <bce-authorization-string>  \n",
    "content-type: application/json  \n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "GET /v1/media/speech?source=vod%3a%2f%2fmda-fhepatsnpn4rk9z HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HTTP/1.1 200 OK\n",
    "\n",
    "{\n",
    "\t\"source\": \"vod://mda-fhepatsnpn4rk9z\",\n",
    "\t\"type\": \"scenario_classify\"\n",
    "\t\"status\": \"FINISHED\",\n",
    "\t\"result\": \"{\\\"results\\\":[{\\\"scenario\\\":\\\"女神\\\",\\\"probability\\\":0.7180786728858948}],\\\"featureUrl\\\":\\\"http://bj.bcebos.com/vca-persistence/subtask/ikbp378443mii55pafp_middle.json\\\"}\"\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 取消视频分析\n",
    "请求语法  \n",
    "'''\n",
    "PUT /v{version}/media HTTP/1.1   \n",
    "host: vca.bj.baidubce.com   \n",
    "authorization: <bce-authorization-string>   \n",
    "content-type: application/json   \n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "PUT /v1/media?source=bos%3a%2f%2ftestbucket%2fdir%2fvideo.mp4&cancel HTTP/1.1\n",
    "host: vca.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HTTP/1.1 200 OK"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 分析结果\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "{\n",
    "    \"results\":[\n",
    "        {\n",
    "            \"type\":\"figure\",\n",
    "            \"result\":[\n",
    "                {\n",
    "                    \"attribute\":\"艾宝俊\",\n",
    "                    \"confidence\":75.11,\n",
    "                    \"source\":\"face_recognition\",\n",
    "                    \"version\": \"V1\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":1,\n",
    "                            \"end\":4\n",
    "                        }\n",
    "                    ]\n",
    "                },\n",
    "                {\n",
    "                    \"attribute\":\"艾宝俊\",\n",
    "                    \"confidence\":75.11,\n",
    "                    \"source\":\"private_face\",\n",
    "                    \"version\": \"V1\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":1,\n",
    "                            \"end\":4\n",
    "                        }\n",
    "                    ]\n",
    "                },\n",
    "                {\n",
    "                    \"attribute\":\"艾宝俊\",\n",
    "                    \"confidence\":100,\n",
    "                    \"source\":\"knowledge_graph\",\n",
    "                    \"version\": \"V1\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":1,\n",
    "                            \"end\":4\n",
    "                        }\n",
    "                    ]\n",
    "                }\n",
    "            ]\n",
    "        },\n",
    "        {\n",
    "            \"type\":\"logo\",\n",
    "            \"result\":[\n",
    "                {\n",
    "                    \"attribute\":\"美拍\",\n",
    "                    \"confidence\":58.73,\n",
    "                    \"source\":\"logo\",\n",
    "                    \"version\": \"V1\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":4,\n",
    "                            \"end\":6\n",
    "                        }\n",
    "                    ]\n",
    "                },\n",
    "                {\n",
    "                    \"attribute\":\"美拍\",\n",
    "                    \"confidence\":58.73,\n",
    "                    \"source\":\"pivate_logo\",\n",
    "                    \"version\": \"V1\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":4,\n",
    "                            \"end\":6\n",
    "                        }\n",
    "                    ]\n",
    "                }\n",
    "            ]\n",
    "        },\n",
    "        {\n",
    "            \"type\":\"keyword\",\n",
    "            \"result\":[\n",
    "                {\n",
    "                    \"attribute\":\"办案\",\n",
    "                    \"confidence\":64.34,\n",
    "                    \"source\":\"character\",\n",
    "                    \"version\": \"V1\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":4,\n",
    "                            \"end\":5\n",
    "                        }\n",
    "                    ]\n",
    "                },\n",
    "                {\n",
    "                    \"attribute\":\"新闻\",\n",
    "                    \"confidence\":26.63,\n",
    "                    \"source\":\"speech\",\n",
    "                    \"version\": \"V1\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":6,\n",
    "                            \"end\":6\n",
    "                        }\n",
    "                    ]\n",
    "                },\n",
    "                {\n",
    "                    \"attribute\":\"新闻\",\n",
    "                    \"confidence\":26.63,\n",
    "                    \"source\":\"title\",\n",
    "                    \"version\": \"V1\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":6,\n",
    "                            \"end\":6\n",
    "                        }\n",
    "                    ]\n",
    "                }\n",
    "            ]\n",
    "        },\n",
    "        {\n",
    "            \"type\":\"scenario\",\n",
    "            \"result\":[\n",
    "                {\n",
    "                    \"attribute\":\"新闻节目\",\n",
    "                    \"confidence\":28.7,\n",
    "                    \"source\":\"scenario_classify\"\n",
    "                    \"version\": \"V2-5\",\n",
    "                },\n",
    "                {\n",
    "                    \"attribute\":\"新闻\",\n",
    "                    \"confidence\":100,\n",
    "                    \"source\":\"knowledge_graph\",\n",
    "                    \"version\": \"V1\",\n",
    "                }\n",
    "            ]\n",
    "        },\n",
    "        {\n",
    "            \"type\":\"entity\",\n",
    "            \"result\":[\n",
    "                {\n",
    "                    \"attribute\":\"人物特写\",\n",
    "                    \"confidence\":58.73,\n",
    "                    \"source\":\"image_classify\",\n",
    "                    \"version\": \"V2\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":4,\n",
    "                            \"end\":6\n",
    "                        }\n",
    "                    ]\n",
    "                },\n",
    "                {\n",
    "                    \"attribute\":\"人物特写\",\n",
    "                    \"confidence\":58.73,\n",
    "                    \"source\":\"image_classify\",\n",
    "                    \"version\": \"V3\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":4,\n",
    "                            \"end\":6\n",
    "                        }\n",
    "                    ]\n",
    "                },\n",
    "                {\n",
    "                    \"attribute\":\"人物特写\",\n",
    "                    \"confidence\":58.73,\n",
    "                    \"source\":\"object_detect\",\n",
    "                    \"version\": \"V1\",\n",
    "                    \"time\":[\n",
    "                        {\n",
    "                            \"start\":4,\n",
    "                            \"end\":6\n",
    "                        }\n",
    "                    ]\n",
    "                }\n",
    "            ]\n",
    "        },\n",
    "        {\n",
    "            \"type\":\"knowledge_graph\",\n",
    "            \"result\":[\n",
    "                {\n",
    "                    \"attribute\":\"林子大(夏雨)\",\n",
    "                    \"confidence\":100,\n",
    "                    \"source\":\"knowledge_graph\",\n",
    "                    \"version\": \"V1\",\n",
    "                }\n",
    "            ]\n",
    "        }\n",
    "    ]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
